package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.mapper.DishMapper;
import com.sky.mapper.Setmeal_dishMapper;
import com.sky.result.Result;
import com.sky.service.impl.SetmealServiceImpl;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController("userSetmealController")
@Slf4j
@Api(tags = "套餐浏览模块")
@RequestMapping("/user/setmeal")
public class SetmealController {
    @Autowired
    private SetmealServiceImpl setmealService;
    @Autowired
    private Setmeal_dishMapper setmeal_dishMapper;
    @Autowired
    private DishMapper dishMapper;
    @GetMapping("/list")
    @Cacheable(cacheNames = "SetmealShowBycategoryId_",key = "#categoryId")
    @ApiOperation("根据分类id查询套餐")
    public Result getBycategoryId(String categoryId){
        List<Setmeal> setmeal_list = setmealService.getBycategoryId(Integer.parseInt(categoryId));
        return Result.success(setmeal_list);
    }
    @GetMapping("/dish/{id}")
    @ApiOperation("查询单个套餐下的所有菜品")
    public Result get_Alldishes_Of_setmeal(@PathVariable String id){
        List<DishItemVO> list = setmealService.getvos(Long.parseLong(id));
        return Result.success(list);
    }
}
